<template>
  <CommonCard title="累计用户数" value="1,068,698">
    <template v-slot:chart>
      <v-chart :option="getOption()" />
    </template>
    <template v-slot:footer>
      <div class="total-users-footer">
        <span>日同比 </span>
        <span class="emphasis">8.73%</span>
        <div class="increase" />
        <span class="month">月同比 </span>
        <span class="emphasis">39.43%</span>
        <div class="decrease" />
      </div>
    </template>
  </CommonCard>
</template>

<script>
import commonCardMixin from '../mixins/commonCardMixin'
export default {
  mixins: [commonCardMixin],
  methods: {
    getOption() {
      return {
        xAxis: {
          type: 'value',
          show: false
        },
        yAxis: {
          type: 'category',
          show: false
        },
        series: [
          {
            type: 'bar',
            stack: '总量', // stack 将两条数据合并成一条
            data: [200],
            barWidth: 10,
            itemStyle: {
              color: '#45C946'
            }
          },
          {
            type: 'bar',
            stack: '总量',
            data: [249],
            itemStyle: {
              color: '#eee'
            }
          },
          {
            type: 'custom',
            stack: '总量',
            data: [200],
            renderItem: (params, api) => {
              const value = api.value(0) // api.value会获取我们data中的第一个值
              const endPoint = api.coord([value, 0]) // api.coord将数据和坐标系关联

              return {
                type: 'group',
                position: endPoint,
                children: [
                  {
                    type: 'path',
                    shape: {
                      d:
                        'M300.74544043 433.43291003c-18.04012654-18.87399937-5.28797393-51.17131722 20.21633121-51.17131724l382.48322394 0c25.50430513 0 38.25645774 32.29731787 20.21633121 51.17131724l-81.27209205 85.01435051-109.9695199 115.05411031c-11.16576039 11.67421947-29.26690202 11.67421947-40.43266242 0l-109.96951995-115.05411031-81.27209204-85.01435051z',
                      x: -5,
                      y: -20,
                      width: 10,
                      height: 10,
                      // layout 会根据width、height、x、y，缩放PathData 用于指定缩放策略
                      // center 保持原来的PathData的长宽比，居于矩形中，尽可能撑大但不会超出矩形
                      // cover PathData拉伸为矩形的长宽比，完全填满矩形，不会超出矩形
                      layout: 'cover'
                    },
                    style: {
                      fill: '#45c946'
                    }
                  },
                  {
                    type: 'path',
                    shape: {
                      d:
                        'M723.25455957 590.56708997c18.04012654 18.87399937 5.28797393 51.17131722-20.21633121 51.17131724l-382.48322394 0c-25.50430513 0-38.25645774-32.29731787-20.21633121-51.17131724l81.27209205-85.01435051 109.9695199-115.05411031c11.16576039-11.67421947 29.26690202-11.67421947 40.43266242 0l109.96951995 115.05411031 81.27209204 85.01435051z',
                      x: -5,
                      y: 10,
                      width: 10,
                      height: 10,
                      layout: 'cover'
                    },
                    style: {
                      fill: '#45c946'
                    }
                  }
                ]
              }
            }
          }
        ],
        grid: {
          top: 0,
          left: 0,
          bottom: 0,
          right: 0
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.total-users-footer {
  display: flex;
  align-items: center;
  .month {
    margin-left: 10px;
  }
}
</style>
